﻿using System;
using System.Threading;
using hello.csharp.consoleApp.LogicTest;
using hello.csharp.consoleApp.StorageTest;
using hello.csharp.helper;
using NLog;

namespace hello.csharp.consoleApp
{
    class Firster
    {
        private readonly Logger _logger = LogManager.GetCurrentClassLogger();
        private readonly UserStorageTest _userStorageTest;
        private readonly ProductStorageTest _productStorageTest;
        private readonly AccountRegisterTest _registerTest;
        private bool _isLoop = true;

        public Firster(UserStorageTest userStorageTest, ProductStorageTest productStorageTest, AccountRegisterTest registerTest)
        {
            _userStorageTest = userStorageTest;
            _productStorageTest = productStorageTest;
            _registerTest = registerTest;
        }

        private static void PrintInfo()
        {
            Thread.Sleep(50);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("---------------------------------------------");
            Console.WriteLine("Please select a function number:");
            Console.WriteLine("10. (sqlite)user storage insert test.");
            Console.WriteLine("11. (sqlite)users(8000) storage insert test.");
            Console.WriteLine("40. (sqlite)user storage logic delete test.");
            Console.WriteLine("---");
            Console.WriteLine("20. (mongodb)product storage test.");
            Console.WriteLine("---");
            Console.WriteLine("50. (logic)user register test.");
            Console.WriteLine("101. GetRandomString(5).");
            Console.WriteLine("0. exit.");
            Console.WriteLine("---------------------------------------------");
            Console.ForegroundColor = ConsoleColor.White;
        }

        public async void Run()
        {
            PrintInfo();
            while (_isLoop)
            {
                var line = Console.ReadLine();
                if (line != null)
                {
                    switch (line.ToLower())
                    {
                        case "10":
                            await _userStorageTest.RunUserInsertTest();
                            break;
                        case "11":
                            await _userStorageTest.Run8000UserInsertTest();
                            Console.WriteLine(">>> Complete！");
                            break;
                        case "20":
                            _productStorageTest.RunProductTest();
                            break;
                        case "40":
                            _userStorageTest.RunUserLogicDeleteTest();
                            break;
                        case "50":
                            _registerTest.Register();
                            break;
                        case "101":
                            GetRandomString();
                            break;
                        case "0":
                            _isLoop = false;
                            break;
                    }
                }
                PrintInfo();
            }
        }

        private void GetRandomString()
        {
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(RandomHelper.GetRandomString(64));
            }
        }

    }
}